var app = getApp(), tcity = require("../../../utils/citys.js");

Page({
    data: {
        tabIndex: 0,
        currentTab: 0,
        isEmpty: !1,
        hasMore: !0,
        pageIndex: 1,
        hasSlide: !1,
        indicatorDots: !0,
        autoplay: !0,
        interval: 5e3,
        duration: 1e3,
        circular: !0,
        psize: 10,
        paihang: 1,
        is_load_more: !0,
        imgUrls: "",
        provinces: [],
        province: "",
        citys: [],
        city: "",
        countys: [],
        county: "",
        s_key: "",
        value: [ 0, 0, 0 ],
        values: [ 0, 0, 0 ],
        industryid: "",
        condition: !1,
        conditionb: !1,
        _is_load: !0
    },
    bindChange: function(a) {
        var t = a.detail.value, e = this.data.values, n = this.data.cityData;
        if (t[0] == e[0]) if (t[1] == e[1]) t[2] == e[2] || this.setData({
            county: this.data.countys[t[2]],
            values: t
        }); else {
            for (var i = [], s = 0; s < n[t[0]].sub[t[1]].sub.length; s++) i.push(n[t[0]].sub[t[1]].sub[s].name);
            this.setData({
                city: this.data.citys[t[1]],
                countys: i,
                values: t,
                value: [ t[0], t[1], 0 ]
            });
        } else {
            for (var o = [], d = [], r = 0; r < n[t[0]].sub.length; r++) o.push(n[t[0]].sub[r].name);
            for (var u = 0; u < n[t[0]].sub[0].sub.length; u++) d.push(n[t[0]].sub[0].sub[u].name);
            this.setData({
                province: this.data.provinces[t[0]],
                city: n[t[0]].sub[0].name,
                citys: o,
                county: n[t[0]].sub[0].sub[0].name,
                countys: d,
                values: t,
                value: [ t[0], 0, 0 ]
            });
        }
    },
    onLoad: function(a) {
        var t = this;
        app.util.footer(this), app.util.getUserInfo(function(a) {
            t.setData({
                userInfo: a
            });
        }), tcity.init(t);
        for (var e = t.data.cityData, n = [], i = [], s = [], o = 0; o < e.length; o++) n.push(e[o].name);
        for (var d = 0; d < e[0].sub.length; d++) i.push(e[0].sub[d].name);
        for (var r = 0; r < e[0].sub[0].sub.length; r++) s.push(e[0].sub[0].sub[r].name);
        t.setData({
            provinces: n,
            citys: i,
            countys: s,
            province: e[0].name,
            city: e[0].sub[0].name,
            county: e[0].sub[0].sub[0].name
        }), app.util.request({
            url: "entry/wxapp/GetIndustry",
            data: {
                m: "bbyscm_card"
            },
            success: function(a) {
                t.setData({
                    industry: a.data.data,
                    indusname: a.data.data.name
                });
            }
        }), app.util.request({
            url: "entry/wxapp/GetBanner",
            data: {
                m: "bbyscm_card"
            },
            success: function(a) {
                0 == a.data.errno && t.setData({
                    imgUrls: a.data.data,
                    hasSlide: !0
                });
            },
            fail: function() {},
            complete: function() {}
        }), app.util.request({
            url: "entry/wxapp/Setup",
            data: {
                m: "bbyscm_card"
            },
            success: function(a) {
                t.setData({
                    setup: a.data.data,
                    industryname: "全部" + a.data.data.z_indus
                });
            }
        }), app.util.request({
            url: "entry/wxapp/GetCard",
            data: {
                m: "bbyscm_card"
            },
            success: function(a) {
                0 == a.data.errno && (a.data.data ? 0 == a.data.data.akey ? t.setData({
                    card_info: a.data.data,
                    cardid: a.data.data.id,
                    avater: a.data.data.avater,
                    mobile: a.data.data.mobile,
                    cardname: a.data.data.cardname
                }) : t.setData({
                    _is_load: !1,
                    is_akey: !0
                }) : (wx.showModal({
                    title: "提示",
                    content: "你还没有创建名片，不能使用收藏夹功能",
                    confirmText: "创建名片",
                    success: function(a) {
                        a.confirm ? wx.navigateTo({
                            url: "../../card/edit/card-edit"
                        }) : a.cancel && t.setData({
                            _is_load: !1,
                            no_card: !0
                        });
                    }
                }), t.setData({
                    _is_load: !1,
                    no_card: !0
                })));
            }
        });
    },
    onReady: function() {},
    onShow: function() {
        this.setData({
            is_load_more: !0,
            pageIndex: 1,
            data: []
        }), this.onPullDownRef(1), this.setData({
            sysinfo: app.globalData.sysinfo
        });
    },
    onPullDownRef: function(a) {
        var t = this, e = t.data.data;
        a = a || !1;
        var n = {};
        n.type = [ "popularity", "collect" ][this.data.tabIndex], n.pageIndex = t.data.pageIndex, 
        n.s_key = t.data.s_key, n.currentTab = t.data.currentTab, n.lon = wx.getStorageSync("longitude"), 
        n.lat = wx.getStorageSync("latitude"), n.psize = t.data.psize, n.province = t.data.province, 
        n.city = t.data.city, n.county = t.data.county, n.industryid = t.data.industryid, 
        n.m = "bbyscm_card", app.util.request({
            url: "entry/wxapp/GetTopColle",
            data: n,
            success: function(a) {
                0 == a.data.errno && (e = e.concat(a.data.data.list), t.setData({
                    data: e,
                    gtotal: a.data.data.gtotal,
                    _is_load: !1
                }));
            },
            fail: function() {
                t.setData({
                    is_load_more: !1,
                    _is_load: !1
                });
            }
        });
    },
    open: function(a) {
        var t = parseInt(a.currentTarget.dataset.tabIndex);
        this.setData({
            tabIndex: t
        }), this.setData({
            is_load_more: !0,
            pageIndex: 1,
            data: [],
            _is_load: !0
        }), this.setData({
            condition: !this.data.condition
        }), this.onPullDownRef(1);
    },
    open2: function(a) {
        var t = parseInt(a.currentTarget.dataset.tabIndex);
        this.setData({
            tabIndex: t
        }), this.setData({
            is_load_more: !0,
            pageIndex: 1,
            data: [],
            _is_load: !0
        }), this.setData({
            conditionb: !this.data.conditionb
        }), this.setData({
            industryid: a.target.dataset.id,
            industryname: a.target.dataset.name
        }), this.onPullDownRef(1);
    },
    open3: function(a) {
        this.setData({
            condition: !this.data.condition
        });
    },
    open4: function(a) {
        this.setData({
            conditionb: !this.data.conditionb
        });
    },
    search_clist: function(a) {
        this.setData({
            is_load_more: !0,
            pageIndex: 1,
            data: [],
            _is_load: !0
        }), this.setData({
            s_key: a.detail.value
        }), this.onPullDownRef(1);
    },
    swichNav: function(a) {
        var t = this;
        if (t.data.currentTab === a.currentTarget.dataset.current) return !1;
        t.setData({
            currentTab: a.currentTarget.dataset.current,
            _is_load: !0
        }), this.setData({
            is_load_more: !0,
            pageIndex: 1,
            data: [],
            _is_load: !0
        }), this.onPullDownRef(1), 0 == t.data.currentTab ? (this.setData({
            is_load_more: !0,
            pageIndex: 1,
            data: [],
            _is_load: !0
        }), this.onPullDownRef(1)) : 1 == t.data.currentTab ? "" == wx.getStorageSync("latitude") && "" == wx.getStorageSync("longitude") ? wx.getLocation({
            complete: function(a) {
                wx.setStorageSync("latitude", a.latitude), wx.setStorageSync("longitude", a.longitude), 
                this.setData({
                    is_load_more: !0,
                    pageIndex: 1,
                    data: [],
                    _is_load: !0
                }), this.onPullDownRef(1);
            }
        }) : (this.setData({
            is_load_more: !0,
            pageIndex: 1,
            data: [],
            _is_load: !0
        }), this.onPullDownRef(1)) : 2 == t.data.currentTab && (this.setData({
            is_load_more: !0,
            pageIndex: 1,
            data: [],
            _is_load: !0
        }), this.onPullDownRef(1));
    },
    onHide: function() {},
    onReachBottom: function() {
        this.data.pageIndex < this.data.gtotal && (this.setData({
            pageIndex: this.data.pageIndex + 1
        }), this.onPullDownRef(1));
    },
    onUnload: function() {},
    onNavigateTap2: function(a) {
        JSON.stringify(a.detail.value);
        var t = a.detail.formId, e = a.currentTarget.id;
        app.util.request({
            url: "entry/wxapp/PostFormid",
            data: {
                m: "bbyscm_card",
                form_id: t
            }
        }), wx.navigateTo({
            url: "../info/info?card_id=" + e
        });
    },
    onNavigateTaptb: function(a) {
        var t = a.currentTarget.dataset.url, e = a.currentTarget.dataset.wx_appid, n = a.currentTarget.dataset.wx_path;
        e ? wx.navigateToMiniProgram({
            appId: e,
            path: n,
            extraData: {
                foo: "bar"
            },
            envVersion: "develop",
            success: function(a) {}
        }) : wx.navigateTo({
            url: "../info/info?card_id=" + t
        });
    },
    onPullDownRefresh: function() {},
    nav_home: function() {
        wx.switchTab({
            url: "/pages/card/index/index"
        });
    },
    nav_back: function() {
        wx.navigateBack({
            delta: 1
        });
    },
    AI_delete: function(a) {
        console.log("提交返回2", a), JSON.stringify(a.detail.value);
        var t = a.currentTarget.id;
        app.util.request({
            url: "entry/wxapp/AI_delete",
            data: {
                m: "bbyscm_card",
                id: t
            },
            success: function(a) {
                this.onPullDownRef(1);
            }
        });
    },
    tap_scanner: function(a) {
        wx.navigateTo({
            url: "../ai_ocr/ai_ocr"
        });
    }
});